#!/usr/bin/python
#coding: utf8

import sys
import os
import subprocess 

# pongo acá algunos resultados, el que mejor anduvo es el Ranker

# valuator:    weka.attributeSelection.InfoGainAttributeEval 
# Search:weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N -1
ranker_info_gain = [1,685,684,676,1441,1432,1442,678,686,1440,691,713,712,1446,1434,1522,256,266,265,264,707,327,1437,258,271,319,1436,277,1330,321,328,329,279,285,270,286,333,663,1332,1331,664,1394,1512,1513,1392,617,1339,1395,665,618,690,1340,655,1343,1435,1335,1393,1341,243,706,616,298,1311,1310,1321,1391,687,1322,287,1342,1338,306,291,661,292,689,598,307,300,78,1337,72,1320,308,624,334,1309,629,681,657,313,83,596,244,245,235,640,71,133,597,679,143,600,70,583,680,135,80,1445,1403,1547,134,1511,578,237,332,141,595,626,797,1406,682,943,672,1548,1398,604,121,117,785,786,436,1405,249,601,118,111,81,1401,644,312,652,944,330,250,518,662,584,529,651,137,68,1404,1085,628,1390,109,88,1481,523,784,795,667,643,699,607,322,96,1377,620,1376,627,1314,142,324,1380,683,668,677,592,688,122,796,608,216,124,331,1528,123,224,1443,181,552,457,288,430,1028,103,824,574,1562,102,73,63,323,1318,458,1066,594,493,537,1400,1402,217,1082,223,257,1017,1016,398,892,1308,97,576,886,634,933,932,673,550,791,1510,1539,387,182,1470,1550,1475,1549,1551,180,1474,1473,485,1319,940,395,94,1523,833,1425,1484,1168,733,221,1363,90,731,526,519,527,520,499,727,501,503,522,524,502,728,525,730,521,500,729,732,504,514,735,513,734,512,511,738,737,736,497,739,740,505,741,508,507,506,509,517,510,742,515,516,498,477,496,461,449,448,447,446,445,450,451,452,456,459,455,453,454,444,443,442,431,432,429,434,428,433,435,441,439,440,438,743,437,460,462,495,463,484,483,482,481,480,486,487,488,492,494,491,489,490,479,478,528,466,467,465,469,464,468,470,476,474,475,473,471,472,726,554,725,621,606,605,603,602,692,609,610,611,615,675,614,612,613,427,599,693,588,589,587,700,586,590,591,694,696,695,697,593,698,619,622,585,623,660,647,646,645,666,659,658,648,653,654,656,649,650,642,641,669,630,631,625,633,674,632,635,670,639,671,638,636,637,701,702,530,553,718,545,544,543,542,717,546,547,714,549,715,548,716,541,719,540,724,533,532,723,531,534,722,720,538,539,536,721,535,551,555,703,556,571,570,569,568,567,572,573,575,581,582,580,577,579,566,565,704,711,559,558,561,557,560,710,705,563,564,562,709,708,1584,348,426,146,147,149,145,144,140,139,138,148,150,101,157,158,151,156,155,154,153,152,136,132,131,112,113,130,110,108,107,106,105,114,115,116,127,129,128,126,119,125,120,159,160,161,192,193,185,191,190,189,188,187,194,195,196,201,203,202,200,197,199,198,186,184,162,168,169,183,167,166,165,164,163,170,171,172,177,179,178,176,173,175,174,104,100,205,29,30,32,28,27,26,25,24,31,33,99,40,41,34,39,38,37,36,35,23,22,21,8,9,20,7,6,5,4,3,10,11,12,17,19,18,16,13,15,14,42,43,44,79,82,66,77,76,75,74,69,84,85,86,93,98,95,92,87,91,89,67,65,45,51,52,64,50,49,48,47,46,53,54,55,60,62,61,59,56,58,57,204,206,425,367,368,370,366,365,364,363,362,369,371,339,378,379,372,377,376,375,374,373,361,360,359,346,347,358,345,344,343,342,341,745,349,350,355,357,356,354,351,353,352,380,381,382,413,414,406,412,411,410,409,408,415,416,417,422,424,423,421,418,420,419,407,405,383,390,391,404,389,388,386,385,384,392,393,394,401,403,402,400,396,399,397,340,338,207,241,242,247,240,239,238,236,234,246,248,337,260,261,251,259,255,254,253,252,233,232,231,213,214,230,212,211,210,209,208,215,218,219,227,229,228,226,220,225,222,262,263,267,310,311,299,309,305,304,303,302,314,315,316,326,336,335,325,317,320,318,301,297,268,276,278,296,275,274,273,272,269,280,281,282,293,295,294,290,283,289,284,744,793,746,1265,1266,1263,1264,1262,1268,1259,1260,1261,1267,1269,1280,1277,1278,1275,1276,1274,1270,1271,1272,1273,1258,1257,1256,1242,1243,1240,1241,1239,1255,1236,1237,1238,1244,1245,1246,1253,1254,1247,1252,1251,1250,1249,1248,1279,1281,747,1317,1323,1315,1316,1313,1325,1306,1307,1312,1324,1326,1282,1345,1346,1336,1344,1334,1327,1328,1329,1333,1305,1304,1303,1289,1290,1287,1288,1286,1302,1283,1284,1285,1291,1292,1293,1300,1301,1294,1299,1298,1297,1296,1295,1235,1234,1233,1172,1173,1170,1171,1169,1175,1165,1166,1167,1174,1176,1232,1184,1185,1182,1183,1181,1177,1178,1179,1180,1164,1163,1162,1148,1149,1146,1147,1145,1161,1142,1143,1144,1150,1151,1152,1159,1160,1153,1158,1157,1156,1155,1154,1186,1187,1188,1219,1220,1217,1218,1216,1211,1213,1214,1215,1221,1222,1223,1230,1231,1224,1229,1228,1227,1226,1225,1212,1210,1189,1196,1197,1194,1195,1193,1209,1190,1191,1192,1198,1199,1200,1207,1208,1201,1206,1205,1204,1203,1202,1347,1348,1349,1509,1514,1507,1508,1506,1516,1503,1504,1505,1515,1517,1476,1527,1529,1525,1526,1524,1518,1519,1520,1521,1502,1501,1500,1486,1487,1483,1485,1482,1499,1478,1479,1480,1488,1489,1490,1497,1498,1491,1496,1495,1494,1493,1492,1530,1531,1532,1570,1571,1568,1569,1567,1561,1564,1565,1566,1572,1573,1574,1581,1582,1575,1580,1579,1578,1577,1576,1563,1560,1533,1541,1542,1538,1540,1537,1559,1534,1535,1536,1543,1544,1545,1557,1558,1546,1556,1555,1554,1553,1552,1477,1472,1350,1384,1385,1382,1383,1381,1387,1375,1378,1379,1386,1388,1471,1410,1411,1408,1409,1407,1389,1396,1397,1399,1374,1373,1372,1357,1358,1355,1356,1354,1371,1351,1352,1353,1359,1360,1361,1369,1370,1362,1368,1367,1366,1365,1364,1412,1413,1414,1457,1458,1455,1456,1454,1449,1451,1452,1453,1459,1460,1461,1468,1469,1462,1467,1466,1465,1464,1463,1450,1448,1415,1422,1423,1420,1421,1419,1447,1416,1417,1418,1424,1426,1427,1439,1444,1428,1438,1433,1431,1430,1429,1141,1140,1139,879,880,877,878,876,882,873,874,875,881,883,848,893,894,890,891,889,884,885,887,888,872,871,870,856,857,854,855,853,869,850,851,852,858,859,860,867,868,861,866,865,864,863,862,895,896,897,928,929,926,927,925,920,922,923,924,930,931,934,942,945,935,941,939,938,937,936,921,919,898,905,906,903,904,902,918,899,900,901,907,908,909,916,917,910,915,914,913,912,911,849,847,947,777,778,775,776,774,780,771,772,773,779,781,846,1583,794,790,792,789,782,783,787,788,770,769,768,754,755,752,753,751,767,748,749,750,756,757,758,765,766,759,764,763,762,761,760,798,799,800,832,834,830,831,829,823,826,827,828,835,836,837,844,845,838,843,842,841,840,839,825,822,801,808,809,806,807,805,821,802,803,804,810,811,812,819,820,813,818,817,816,815,814,946,948,1138,1076,1077,1074,1075,1073,1079,1070,1071,1072,1078,1080,1044,1090,1091,1088,1089,1087,1081,1083,1084,1086,1069,1068,1067,1052,1053,1050,1051,1049,1065,1046,1047,1048,1054,1055,1056,1063,1064,1057,1062,1061,1060,1059,1058,1092,1093,1094,1125,1126,1123,1124,1122,1117,1119,1120,1121,1127,1128,1129,1136,1137,1130,1135,1134,1133,1132,1131,1118,1116,1095,1102,1103,1100,1101,1099,1115,1096,1097,1098,1104,1105,1106,1113,1114,1107,1112,1111,1110,1109,1108,1045,1043,949,979,980,977,978,976,982,973,974,975,981,983,1042,991,992,989,990,988,984,985,986,987,972,971,970,956,957,954,955,953,969,950,951,952,958,959,960,967,968,961,966,965,964,963,962,993,994,995,1029,1030,1026,1027,1025,1020,1022,1023,1024,1031,1032,1033,1040,1041,1034,1039,1038,1037,1036,1035,1021,1019,996,1003,1004,1001,1002,1000,1018,997,998,999,1005,1006,1007,1014,1015,1008,1013,1012,1011,1010,1009,2]

# Evaluator:    weka.attributeSelection.CfsSubsetEval 
# Search:weka.attributeSelection.GreedyStepwise -T -1.7976931348623157E308 -N -1
greedy_cfs_subset = [1,68,78,83,103,133,137,180,216,235,245,256,258,270,271,277,279,285,291,292,313,327,398,485,529,552,598,640,652,655,663,664,676,678,683,684,685,686,691,706,712,713,733,886,943,1016,1066,1321,1330,1343,1376,1391,1432,1440,1441,1442,1547]
ranksearch_cfs_subset = [1,72,103,135,137,182,216,245,256,258,264,265,266,270,271,277,313,327,398,457,485,529,552,598,640,655,664,665,676,678,683,684,685,686,691,706,707,712,713,733,886,943,1028,1066,1330,1331,1332,1343,1391,1394,1432,1434,1436,1437,1440,1441,1442,1446,1522]


def extrar_atributos():
    path = "~/Repos/ith-tp2/opensmile-2.0-rc1/opensmile/config/IS10_paraling.conf"
    for i in os.listdir("../tp2-dev/"):
        if i.endswith(".wav"): 
            print "Extrayendo attr de: ", i
            # $DIR/SMILExtract -C $DIR/config/IS10_paraling.conf -I in.wav -O out.arff
            cmd = "SMILExtract -C Configs/IS10_paraling.conf -I ../tp2-dev/"+ i + " -O output.arff -instname "+ i[4] +" -classes {m,f} -classlabel " + i[4]
            print cmd
            p = subprocess.Popen(cmd , shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            p.wait()
            # output = process.communicate()[0]
            continue
        else:
            continue

# Selecciona los 36 atributos de Ranker que fue lo que anduvo mejor.
def seleccionar_atributos():
    print ranker_info_gain[:36]

extrar_atributos()
# seleccionar_atributos()  